<template>
    <div class="port-page">
        <!-- 顶部按钮 -->
        <div class="but1">
        	<router-link to="/home">
			<el-button type="warning" size="small" class="add btn"   style='margin-right: 5px;' icon="el-icon-menu">首页</el-button>
		</router-link>
		<router-link :to="{path:'/home',query: {id:vbjid,frompage:'zy'}}">
			<el-button type="warning" size="small"  class="add btn" icon="el-icon-caret-left">返回</el-button>
		</router-link>
		<div class="search-item">
            	 <span>作业类型</span>
                <el-select v-model="vcdname"  @change="search" class="code-search" placeholder="请选择作业类型">
                      <el-option :label="v.cdname" :value="v.cdname" v-for="v in comcdlist"></el-option>
                </el-select>
            </div>
        <el-button type="success" class="add btn" @click='iscanedit=true' v-if="!iscanedit" icon="edit">启用编辑</el-button>
        <el-button type="danger" class="add btn" @click='iscanedit=false'  v-if="iscanedit"  icon="edit">关闭编辑</el-button>
        <el-button type="success" class="add btn" @click='fstj()' v-if="iscanedit" icon="edit">提交分数</el-button>
	    </div>
        <!-- 数据表格展示区域 -->
        <el-table
            :data="dataList"
            stripe
             border
             size="small"
            align="center"
            class="admin-table"
            @select="checkSelect"
            @select-all="checkall">
            <!--<el-table-column type="selection" width="55"></el-table-column>-->
            <div slot='empty'>
                <img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
                <span style="vertical-align: middle;">暂时还没有内容哦!</span>
            </div>
            <el-table-column
                :prop="v.prop"
                :label="v.label"
                v-for="(v,index) in portTitleList"
                align="center"
                show-overflow-tooltip
                v-if="v.hide != 0"
                :formatter="addee"
                :align="v.align || 'center'"
                :fixed="v.fixed"
                :class-name="v.columnStyle"
                :width="v.width"
                :min-width="v.minWidth"
                :header-align="v.headerAlign || 'center'"
                >
                <template scope="scope">
                    <div slot="reference" :style="tableCellControl(scope)" v-if="scope.column.property === 'score' && iscanedit ">
                    <el-select v-model="scope.row[scope.column.property]" >
	                	<el-option label="A+" value="12"></el-option>
	                    <el-option label="A"  value="11"></el-option>
	                    <el-option label="A-" value="10"></el-option>
	                    <el-option label="B+" value="9"></el-option>
	                    <el-option label="B"  value="8"></el-option>
	                    <el-option label="B-" value="7"></el-option>
	                    <el-option label="C+" value="6"></el-option>
	                    <el-option label="C"  value="5"></el-option>
	                    <el-option label="C-" value="4"></el-option>
	                    <el-option label="D+" value="3"></el-option>
	                    <el-option label="D"  value="2"></el-option>
	                    <el-option label="D-" value="1"></el-option>
	                    <el-option label="未提交" value="0"></el-option>
	                    <el-option label="未录入" value="-1"></el-option>
                    </el-select>
                       <!--<el-input class="content-input"   v-model="scope.row[scope.column.property]" ></el-input>-->
                   </div>
                   <div slot="reference" v-else>
                        {{scope.row[scope.column.property]}}
                    </div>
                 </template>
            </el-table-column>
            <el-table-column label="操作" width="130px" align="center" >
                <template scope="scope">
                   <el-button size="mini" type="success"   @click="componentsShow('info',scope)">学生详情</el-button>
                </template>
            </el-table-column>
        </el-table>

        <!-- 各个组件显示区域 -->
        <!-- 动画加载 -->
        <LoadingComponent v-show="isLoading"></LoadingComponent>
        <!-- info组件 -->
        <infoComponent v-if="portComponents.info.toggle" @close="componentsHide" :params="portComponents.info.params"></infoComponent>
        <!-- 子路由显示区域 -->
        <router-view class="port-view"></router-view>
    </div>
</template>
<script>
    import { mapState } from 'vuex'
    import LoadingComponent from 'components/loading'
    import InfoComponent from 'view/educa/classManage/student/info'
    import qs from 'qs'
    export default {
        components: { LoadingComponent,InfoComponent },
        data () {
            return {

            /*模糊搜索条件*/

               vkeyword:'', // keyword

               vbjid:this.$route.query.iid, // 班级id
               vcdname:'',

               vzylx:'', // 作业类型

//             vday:'', // day
               iscanedit:false,//显示编辑的数字框
				multipleDelNum:'', //获取批量选择的数据
                dataList: [],  //表格数据
                comboxlist:[], //下拉框 动态的
                comlxlist:[],
                comcdlist:[],
                vcomautovalue:'',//下拉框name 动态的
                vcomgdvalue:'',//下拉框name 固定的

				/*动画加载*/
                isLoading: true,//动画加载
                searchLoading: false,//搜索按钮触发按钮动画
                /*分页属性设置*/
                layout: 'total, sizes, prev, pager, next, jumper',//组件布局
			    pageindex: this.$store.state.pageindex,//当前分页页码
                pagesizes: this.$store.state.pagesizes,//显示个数的选择器选项
                pagesize: this.$store.state.pagesize,//每页显示条目数
                total: 0,//总条数

                /*组件区域*/
                portComponents: {
                    /* info */
                    info: {
                        type: 'info',
                        toggle: false,
                        params: '',
                        data: {}
                    }
                },
                /*
                    prop :  接口参数名
                    label : 接口中文名
                    hide : 是否隐藏这一列
                    align : 这一列对齐顺序 ： left,right,center
                    headerAlign : 这一列表头对齐方式 ： left,right,center
                */
                portTitleList: [
                    {
                        prop:'id',
                        label:'id',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'bjmc',
                        label:'班级名称',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'xsmc',
                        label:'学生名称',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'score',
                        label:'作业分数',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'lx',
                        label:'类型  ',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'gh',
                        label:'工号',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'zylx',
                        label:'作业类型 ',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'lsmc',
                        label:'老师名称',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'crtime',
                        label:'录入日期',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'zt',
                        label:'状态',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    }

                ]
            }
        },
        created () {
            //加载页面时调用
            this.$store.dispatch('changeTitle',this.$route.query.bjmc+'作业成绩');//修改title
            this.$store.dispatch('changeRouterIndex','/educa/workcj');//修改路由
            this.search();//分页获取默认数据
            this.getcomlist(); //加载下拉列表
            this.getcomlxlist();
            this.getcomcdlist();
            this.isLoading = true;//动画开始
        },
        mounted () {
            //加载完成之后event
            this.isLoading = false;//动画结束
        },
        methods: {
			addee(){
				alert(1111)
			},
          fstj(lxtype){
            this.$confirm('确认提交分数么?', '提示', {
    				 confirmButtonText: '确定',
    				 cancelButtonText: '取消',
    				 type: 'warning'
    			 }).then(() => {
             // lxtype  1 =主教 2=助教
              var kqstr="";
              this.dataList.forEach(function(v,i){
                   kqstr=v.xsid+","+v.score+";"+kqstr ;
              })
              if (kqstr==''){
                this.$message.warning('没有找班级学生,不能提交分数');
                 return ;
              }
              var logininfo = JSON.parse(localStorage.logininfo);
              var params2 = qs.stringify({
                  yhid:logininfo.id,
                  xxid:logininfo.xxid,
                  bjid: this.vbjid, // 班级id
                  zylx:this.vcdname,//课次
//                day:this.vday,
                  kqstr:kqstr
                })
              //执行
                  this.axios.post(this.$store.state.api + 'zyscore/updatezycjtj',  params2 )
                  .then(res => {
                    if(res.data.code == 1) {
                       this.search();
                       this.iscanedit=false;
                    } else {
                      this.$message.warning(res.data.msg)
                    }
                  })


    			 }).catch(() => {
    				 this.$message({
    					 type: 'info',
    					 message: '已取消'
    				 });
    			 });

         },
          search () {
		    //查询搜索触发事件
		      var logininfo = JSON.parse(localStorage.logininfo);
              this.searchLoading = true;
              var params2 = qs.stringify({
                    //                    keyword: this.vkeyword, // keyword
                      bjid: this.vbjid, // 班级id
                      zylx: this.vcdname, // 作业类型
//                    day: this.vday, // day
                      yhid:logininfo.id,
                      xxid:logininfo.xxid,
               })
             //执行
                 this.axios.post(this.$store.state.api + 'zyscore/getzylist',  params2 )
                 .then(res => {
//               console.log('1111',res)
                  let data = res.data.data;
                  let list = data.list;
                  this.total = data.totalPage;
                  this.dataList = list;
                  for( var i in this.dataList){
//                	console.log(i,'ssss')
                  	if(this.dataList[i].score=="12"){
                  		 this.dataList[i].score="A+"
                  	}
                  	else if(this.dataList[i].score=="11"){
                  		 this.dataList[i].score="A"
                  	}
                  	else if(this.dataList[i].score=="10"){
                  		 this.dataList[i].score="A-"
                  	}
                  	else if(this.dataList[i].score=="9"){
                  		 this.dataList[i].score="B+"
                  	}
                  	else if(this.dataList[i].score=="8"){
                  		 this.dataList[i].score="B"
                  	}
                  	else if(this.dataList[i].score=="7"){
                  		 this.dataList[i].score="B-"
                  	}
                  	else if(this.dataList[i].score=="6"){
                  		 this.dataList[i].score="C+"
                  	}
                  	else if(this.dataList[i].score=="5"){
                  		 this.dataList[i].score="C"
                  	}
                  	else if(this.dataList[i].score=="4"){
                  		 this.dataList[i].score="C-"
                  	}
                  	else if(this.dataList[i].score=="3"){
                  		 this.dataList[i].score="D+"
                  	}
                  	else if(this.dataList[i].score=="2"){
                  		 this.dataList[i].score="D"
                  	}
                  	else if(this.dataList[i].score=="1"){
                  		 this.dataList[i].score="D-"
                  	}
                  	else if(this.dataList[i].score=="0"){
                  		 this.dataList[i].score="未提交"
                  	}
                  	else if(this.dataList[i].score=="-1"){
                  		 this.dataList[i].score="未录入"
                  	}
                  	
                  }
                  this.searchLoading = false;
                 }).catch(res => {
                  this.searchLoading = false;
				})
          },
          getcomlist(){
          	var logininfo = JSON.parse(localStorage.logininfo);
             var params2 = qs.stringify({
                      yhid:logininfo.id,
                    xxid:logininfo.xxid
               })
             //执行
                 this.axios.post(this.$store.state.api + 'bj/getbj',  params2 )
                 .then(res => {
              let data = res.data.data;
              let list = data.list;
              this.comboxlist = list;
                 }).catch(res => {
				})
          } ,
          getcomlxlist(){
          	var logininfo = JSON.parse(localStorage.logininfo);
             var params2 = qs.stringify({
                      yhid:logininfo.id,
                    xxid:logininfo.xxid,
                    bjid:this.vbjid
               })
             //执行
                 this.axios.post(this.$store.state.api + 'zyscore/getzyfllist',  params2 )
                 .then(res => {
                 let data = res.data.data;
              let list = data.list;
              this.comlxlist = list;
                 }).catch(res => {
				})
          } ,
          getcomcdlist(){
          	var logininfo = JSON.parse(localStorage.logininfo);
             var params2 = qs.stringify({
                     yhid:logininfo.id,
                    xxid:logininfo.xxid,
                    isenable:'Y',
                    pcd:'c005'
               })
             //执行
                 this.axios.post(this.$store.state.api + 'xxcode/list ',  params2 )
                 .then(res => {
//               	console.log(res,'11111111111111')
                 let data = res.data.data;
              let list = data.list;
              this.comcdlist = list;
                 }).catch(res => {
				})
          } ,
          tableCellControl (scope) {
            //表格单元格控制CSS样式
                /*if (scope.row.id == 112 && scope.column.property == "iname") {
                    return {
                        color:"red",
                    }
                }else{
                    return {
                        color:"green",
                    }
                }*/
           },
           handleSizeChange (val) {//每页显示条数触发事件
                this.pagesize = val;
                this.pageindex = 1;
                this.search();
            },
            handleCurrentChange (val) {//分页触发事件
                this.search();
            },
            checkSelect (selection, row) {//点击单选select触发事件
                // console.log(selection, row)
                let strID = [];
                selection.forEach(function(v,i){
                    strID.push(v.id)
                })
                this.multipleDelNum = strID.join(",");
            },
            checkall (selection) {//点击全选select触发事件
                let strID = [];
                selection.forEach(function(v,i){
                    strID.push(v.id)
                })
                this.multipleDelNum = strID.join(",");
            },
            /* 组件的弹框  */
            componentsShow (type,data) { //显示组件
                // console.log(type,data)
                for ( let i in this.portComponents ) {
                    if (type == this.portComponents[i].type) {
                        this.portComponents[i].toggle = true;
                        this.portComponents[i].params = data;
                        if (this.portComponents[i].data.type == 'single') {
                            this.portComponents[i].data.index = data.row.id
                        }else if(this.portComponents[i].data.type == 'multiple'){
                            this.portComponents[i].data.index = this.multipleDelNum;
                        }else{
                            return;
                        }
                        return;
                    }
                }
            },
            componentsHide (setting) { //关闭组件
                // console.log(setting)
                for ( let i in this.portComponents ) {
                    if (setting.type == this.portComponents[i].type) {
                        this.portComponents[i].toggle = false;
                        if (!setting.cancel) {
                           this.search();
                        }
                        return;
                    }
                }
            }
        },
        computed: {
            ...mapState([
                'api'//域名
            ]),
            multipleDeleteDisabled () {
                // console.log(this.multipleDelNum)
                if (this.multipleDelNum) {
                    return false;
                }else{
                    return true
                }
            }
        }
    }
</script>

<style lang="less" scoped>
    .port-page {
        font-size:12px;
        .btn {
            height: 30px;
            margin-left: 0px;
            padding:0 10px;
        }
        .ys2{
	       color: #F7BA2A;
          }
        .code-search {
            height: 30px;
            margin:10px 0 10px 0;
            min-width: 120px;
            max-width: 150px;
        }
        .class-page {
            text-align: left;
            margin-top:10px;
        }
        .search-item {
            display: inline-block;
            /*margin-right:10px;*/
        }
        .but1{
			width: 70%;
			float: left;
			// margin-top: 8px;
		}
		.search{
			width: 30%;
			float: right;
			text-align: right;
		}
    }
</style>
